{extend name="public:base" /}

{block name="body"}
<div class="main" style="padding:15px;">
    <div class="content">
        <span style="margin-left: 0">商品列表</span>
        <div></div>
    </div>
    <table class="layui-table">
        <thead>
        <tr>
            <th style="text-align: center;font-weight: bold">ID</th>
            <th style="text-align: center;font-weight: bold">商品标题</th>
            <th style="text-align: center;font-weight: bold">分类</th>
            <th style="text-align: center;font-weight: bold">原价</th>
            <th style="text-align: center;font-weight: bold">折扣</th>
            <th style="text-align: center;font-weight: bold">现价</th>
            <th style="text-align: center;font-weight: bold">库存</th>
            <th style="text-align: center;font-weight: bold">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="right" id='right'}
        <tr>
            <td style="text-align: center">{$right.id}</td>
            <td style="text-align: center">{$right.title}</td>
            <td style="text-align: center">{$right.cat|getCatName}</td>
            <td style="text-align: center">{$right.price}</td>
            <td style="text-align: center">{$right.discount}</td>
            <td style="text-align: center">
                {if $right.discount <> 0}
                {$right.discount*0.1*$right.price}
                {else/}{$right.price}
                {/if}
            </td>
            <td style="text-align: center">{$right.stock|default=0}</td>

            <td style="text-align: center" >
                <button class="layui-btn layui-btn-xs" id="cart1" onclick="addCart({$right},event)">加入购物车</button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div style="text-align: center">{$rightList|raw}</div>

</div>

<script>
    window.onload=function () {

    }

    function addCart(goods_id,e){
        layer.confirm('确定要增加 "'+goods_id['title']+' "吗?', {
            icon:3,
            btn: ['确定','取消']
        }, function(){
            $.post('/index.php/user/addCart',{'goods_id':goods_id['id']},function(res){
                if(res.status == 0){
                    layer.alert(res.message,{icon:2});
                    $('button').$(this).attr('class','btn btn-default')
                    $('button').$(this).text(data.message)
                }else{
                    layer.msg(res.message);
                    e.target.innerHTML=res.message;
                    // e.target.setAttribute('class','btn btn-default')

                    setTimeout(function () {
                         window.location.reload();
                     },1100);
                }
            },'json');
        });
    }

</script>

{/block}

